package ar.edu.itba.it.cg.grupo01.impl.color;

import java.awt.Color;

import javax.vecmath.Point3d;

import ar.edu.itba.it.cg.grupo01.impl.Camera;

public class LinearVariation extends AbstractVariation {


	@Override
	protected Color apply(final Color shapeColor, final Camera camera, final Point3d closest) {
		
		final float distance = (float) camera.getOrigin().distance(closest);

		final float[] hsb = Color.RGBtoHSB(shapeColor.getRed(), shapeColor.getGreen(),
				shapeColor.getBlue(), null);
		final float hue = hsb[0]; // .58333
		final float saturation = hsb[1]; // .66667
		float brightness = hsb[2]; // .6

		double far=20;
		
		//final float deltaB = (float) -(distance * 0.0001);
		final float deltaB =  (float) (Math.abs( (float) ((far-distance)/2)/(far)));
//		System.out.println(deltaB);
//		System.out.println(distance);
		brightness = (float) (0.1+ deltaB);
		
		

		brightness = brightness + deltaB;

		if (brightness < 0.0f) {
			brightness = 0.0f;
		}

		// Convert HSB to RGB value
		final Color newColor = new Color(Color.HSBtoRGB(hue, saturation,
				brightness));
		return newColor;
	}

}
